//
//  MyCouponViewController.m
//  OrderSeat
//
//  Created by haiming on 13-10-7.
//  Copyright (c) 2013年 wangwei. All rights reserved.
//

#import "MyCouponViewController.h"
#import "CouponView.h"

@implementation MyCouponViewController

- (id)init
{
    self = [super initWithNibClass:[MyCouponViewController class]];
    if (self) {
        
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self setupUI];
}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [[AppDelegate sharedInstance] hideTabBar:self.tabBarController];
}

- (void)setupUI
{
    [self createLeftButton];
    [self setNavigationTitle:@"我的优惠券"];
    
    self.doingCouponView = [self createViewWithType:NewCoupon];
}

- (void)leftButtonClick:(id)sender
{
    [self.navigationController popViewControllerAnimated:YES];
    [[AppDelegate sharedInstance] showTabBar:self.tabBarController];
}

- (CouponView *)createViewWithType:(CouponType)couponType
{
    CGRect frame = CGRectMake(0, _btnOnGoing.bottom, ScreenWidth, ScreenHeight-_btnOnGoing.bottom);
    CouponView *couponView  = [[CouponView alloc] initWithFrame:frame andCouponType:couponType];
    couponView.couponVC = self;
    [self.view addSubview:couponView];
    return couponView;
}

- (IBAction)selOrderAction:(id)sender
{
    _btnOnGoing.selected = _btnExpired.selected = NO;
    UIButton *button = (UIButton*)sender;
    button.selected = !button.selected;
    
    if (!_doingCouponView) self.doingCouponView = [self createViewWithType:NewCoupon];
    if (!_doneCouponView) self.doneCouponView = [self createViewWithType:DoneCoupon];
    
    _doingCouponView.hidden = !_btnOnGoing.selected;
    _doneCouponView.hidden = !_btnExpired.selected;
}


@end